home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Add-Ons / MicroPhone / Open Mike™ / Open Mike™ 003 / Mike's Folder / Funky Functions < prev    next >
Encoding:
Text File  |  1993-03-01  |  4.7 KB  |  67 lines  |  [TEXT/ttxt]

  1. Funky Functions
  2. ===============
  3. by Norman Lee
  4. Copyright © 1993 by Celestin Company
  5. All rights reserved.
  6.  
  7. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage and retrieval system, without permission in writing from the publisher. However, you are permitted to make copies of this work, printed or otherwise, as long as said copies are for your personal use only.
  8.  
  9. Introduction
  10. ------------
  11. Have you ever wished that MicroPhone supported a particular function? Have you ever wanted the Set Variable from date and time command to return the current date and time in the format of your choosing? Do you want to write a set of scripts once and be able to use it in any of your settings documents? If you've answered yes to any of these questions, read on!
  12.  
  13. MicroPhone does not really support the ability to include functions of your own making, unless you are adept at creating XFCNs in a programming language such as Pascal. However, there is a method of faking functions. For the sake of clarity, we'll call our scripted functions "pseudo-functions". For example, if you've created a pseudo-function called "starDate", which returns the current date in the form used by a popular television program, to get this date, run the script called "starDate". The properly formatted date will be returned to you in a variable with the same name as the script. So, for example, you might do the following:
  14.  
  15.   Do Script "'starDate'"
  16.   Alert OK "'Captain''s Log, Star Date ' & starDate & '.'"
  17.  
  18. What sets starDate apart from being a true function is the fact that MicroPhone scripts cannot return values. If they did, you'd be able to do the following:
  19.  
  20.   Set Variable myDate from Expression "starDate"
  21.  
  22. MicroPhone should then look for a script by the same name. If one is found, and the script sets the variable starDate, then starDate should be returned. If no script is found, then MicroPhone should look for the XFCN starDate. If none is found, then look for a true function. If none, then the variable starDate. If no go here, then nothing will be returned. Useful addition to MicroPhone? I think so.
  23.  
  24. Anyway, since MicroPhone does not do this, we'll have to go with our two-line method of creating new pseudo-functions. Since MicroPhone supports modules, let's keep our pseudo-functions in a module called "Extras" and keep the module in the Module Folder. This way, any settings document that wants to, can share the pseudo-functions in Extras.
  25.  
  26. To get you started, I've included my personal copy of Extras. You'll find it in Mike's Folder. Put a copy of it in your Module Folder, which should be in the same location as the MicroPhone application. If you don't have a Module Folder, create it.
  27.  
  28. Here's what's in my Extras module:
  29.  
  30. dateAndTime
  31. coder
  32. reverse
  33. ai
  34.  
  35. These pseudo-functions are described in detail below. In order the make them available to your settings document, include the following script line in your setting document's startup script:
  36.  
  37.   Module Load "'Extras'"
  38.  
  39. Then, whenever you want to use a particular pseudo-function, use the following syntax:
  40.  
  41.   Do Script "'ai'"
  42.   Alert OK "ai"
  43.  
  44. dateAndTime
  45. -----------
  46. This pseudo-function returns the current date and time in my favorite format yy/mm/dd-hh.mm.ss, which allows me to use it as a file name. For example, if today is March 15, 1993, and the time was 2:30 PM, it would return:
  47.  
  48.   93/03/15 - 14.30.22
  49.  
  50. Pretty spiffy, eh? The script that handles this conversion is pretty easy to following, so you should be able to make changes to it to format the date to your own liking.
  51.  
  52. coder
  53. -----
  54. Put what you want to be encrypted or decrypted into the variable "coder". It will be returned to you encrypted or decrypted. This is useful if you want to encrypt your password before writing it to a text file. Then, when you are ready to use it, you can run it through the coder pseudo-function to restore it. The algorithm for encryption and decryption is pretty braindead. Probably wouldn't take more than a few minutes for someone with a good program to break it, but it does keep your password from prying eyes.
  55.  
  56. reverse
  57. -------
  58. This silly pseudo-function returns you whatever string you give it in reverse. For example, if you give it the word "yellow", it will return "wolley".
  59.  
  60. ai
  61. --
  62. Here is another silly pseudo-function. This one returns you a random three word phrase, such as "feed the dog" or "bite the bullet". Take a look at the script if you're interested in how artificial neural networks are created. Not!
  63.  
  64. Final Thoughts
  65. --------------
  66. I hope you enjoyed this article. If there is enough demand, I might do some more functions for a later issue of Open Mike. Until then, keep cool to the thrill of it all!
  67.